﻿
using Net.http;
using System;
using System.Collections.Generic;
namespace HBase {
    public static class LoggerCache {
        private static List<ShowCache> cacheList = new List<ShowCache>();
        public static List<ShowCache> getAll() {
            List<ShowCache> list = new List<ShowCache>();
            lock( cacheList ) {
                clear();
                for( int i = cacheList.Count - 1;i >= 0;i-- ) {
                    list.Add(cacheList[i]);
                }
            }
            return list;
        }

        static void clear() {
            while( true ) {
                if( cacheList.Count == 0 ) {
                    break;
                }
                ShowCache sc = cacheList[0];
                if( DateTime.Now.Ticks - sc.timeTicks.Ticks > 20 * HUtil.ticksSecRate ) {
                    cacheList.RemoveAt(0);
                } else {
                    break;
                }
            }

        }
        public static bool has(int code,String msg) {//在界面上展示20秒之后消失
            lock( cacheList ) {
                clear();
                for( int i = 0;i < cacheList.Count;i++ ) {
                    ShowCache c = cacheList[i];
                    if( msg == c.Msg ) {
                        return true;
                    }
                }
                cacheList.Add(new ShowCache(code,msg));
            }
            return false;
        }
    }

}
